package com.tianshuo.condition.model;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * 实现Condition接口，matches方法，返回true标识是需要跳过, 返回false则不需要跳过
 * Condition接口是springboot中@ConditionOnClassxxx注解的关键
 * @author tianshuo
 */
public class PersonCondition implements Condition {

    Logger logger = LoggerFactory.getLogger(PersonCondition.class);
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {

        logger.info("{}",context);
        logger.info("metadata: {}",metadata);

        if(context.getBeanFactory().containsBean("person")){
            System.out.println("存在 bean");
            return true;
        }

        return false;
    }
}
